package jeye.midlet;

import java.util.Hashtable;

import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.midlet.MIDlet;

import jeye.util.HttpConnector;

public class ApplicationController {
	
	private MIDlet midlet;
	
	private Hashtable applicationCache = new Hashtable();
	
	private HttpConnector connector = new HttpConnector("http://localhost:8888/JEyeWeb/events");
	
	private ScreenFactory screenFactory = new ScreenFactory(this, connector);
	
	protected ApplicationController(MIDlet midlet) {
		this.midlet = midlet;
	}
	
	public Displayable getApplicationScreen(int screenType) {
		return screenFactory.createScreen(screenType);
	}
	
	public void setCurrentDisplay(Displayable displayable) {
		Display display = Display.getDisplay(midlet);
		display.setCurrent(displayable);
	}
	
	public void setCurrentDisplay(int screenType) {
		setCurrentDisplay(screenFactory.createScreen(screenType));
	}

	public Object getFromCache(String key) {
		return applicationCache.get(key);
	}
	
	public void putToCache(String key, Object object) {
		applicationCache.put(key, object);
	}
	
}
